import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nft/provider/LoginProvider.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ClearSetting extends StatefulWidget {
  @override
  _ClearSettingState createState() => _ClearSettingState();
}

class _ClearSettingState extends State<ClearSetting> {
  clearSetting() async {
    //清除状态
    context.read<LoginProvider>().setProductDetailCode("");
    context.read<LoginProvider>().setProductMaxUrl("");
    context.read<LoginProvider>().setIsLogin(false);
    context.read<LoginProvider>().setToken("");
    context.read<LoginProvider>().setUserName("");
    context.read<LoginProvider>().setOpenId("");
    // //清除缓存
    SharedPreferences prefs = await SharedPreferences.getInstance();
    final result = await prefs.remove("phone");
    final result1 = await prefs.remove("isLogin");
    final openid = await prefs.remove("openId");

    // //跳转路由
    Navigator.of(context).pushNamed("tabbar");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: GestureDetector(
          onTap: (){
            Navigator.of(context).pop();
          },
          child: Icon(Icons.arrow_back_ios_rounded),
        ),
        title: Text("设置"),
        centerTitle: true,
      ),
      body: Padding(
        padding: EdgeInsets.all(15),
        child: Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child: ListView(
            children: [
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [],
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    "",
                    style: TextStyle(fontSize: 16, color: Colors.white24),
                  )
                ],
              ),
              InkWell(
                onTap: () async {
                  print("退出登录");
                  BrnDialogManager.showConfirmDialog(context,
                      title: "确定退出登录吗",
                      cancel: '取消',
                      confirm: '确定', onConfirm: () {
                    BrnToast.show("确定", context);
                    clearSetting();
                  }, onCancel: () {
                    BrnToast.show("取消", context);
                    Navigator.of(context).pop();
                  });
                },
                child: Container(
                    alignment: Alignment.center,
                    width: MediaQuery.of(context).size.width,
                    height: 40,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(40),
                        color: Colors.red),
                    child: Text(
                      "退出登录",
                      style: TextStyle(fontSize: 16, color: Colors.white),
                    )),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
